package db

import (
	"fmt"
	"github.com/jinzhu/gorm"
	_ "github.com/jinzhu/gorm/dialects/mysql"
	"time"
)

//获取线上数据库实例
func NetDb() *gorm.DB {
	//链接数据库 "user:password@/dbname?charset=utf8&parseTime=True&loc=Local"

	db, err := gorm.Open("mysql", fmt.Sprintf("%s:%s@(%s:%d)/%s?charset=utf8mb4&parseTime=True&loc=Local",
		"b2broot",
		"#FoyUH%0SGlXj8H#",
		"116.63.168.211",
		3306,
		"new_b2b"))
	db.DB().SetConnMaxLifetime(30 * time.Second)
	if err != nil {
		fmt.Print(err)
	}

	return db
}

//本地数据库实例
func LocalDb() *gorm.DB{
	db, err := gorm.Open("mysql", fmt.Sprintf("%s:%s@(%s:%d)/%s?charset=utf8mb4&parseTime=True&loc=Local",
		"root",
		"aaa...123qwe",
		"localhost",
		23306,
		"mind_ocs_yk"))
	db.DB().SetConnMaxLifetime(30 * time.Second)
	if err != nil {
		fmt.Print(err)
	}
	return db
}
